package com.ljx.funchat.user.service.adatper;

import com.ljx.funchat.user.domain.entity.User;
import com.ljx.funchat.user.domain.entity.UserFriend;
import com.ljx.funchat.user.domain.vo.resp.UserFriendResp;
import com.ljx.funchat.user.domain.vo.resp.UserFriendSearchResp;
import org.springframework.stereotype.Component;

import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

public class UserFriendAdapter {

    public static UserFriend buildUserFriend(Long uid, Long targetId) {
        UserFriend userFriend = new UserFriend();
        userFriend.setUid(uid);
        userFriend.setFriendUid(targetId);
        return userFriend;
    }

    public static List<UserFriendResp> buildUserFriendResp(List<UserFriend> list, Map<Long, User> userMap) {
        return list.stream().map(item -> {
            UserFriendResp res = new UserFriendResp();
            res.setUid(item.getFriendUid());
            res.setActiveStatus(userMap.get(item.getFriendUid()).getActiveStatus());
            return res;
        }).collect(Collectors.toList());
    }

    public static UserFriendSearchResp.UserInfo buildSearch(User user, boolean flag) {
        UserFriendSearchResp.UserInfo userInfo = new UserFriendSearchResp.UserInfo();
        userInfo.setAvatar(user.getAvatar());
        userInfo.setFriend(flag);
        userInfo.setName(user.getName());
        userInfo.setUid(user.getId());
        return userInfo;
    }
}
